/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
package com.wealth.bbs.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wealth.bbs.enums.TopicAppraiseEnum;
import com.wealth.member.entity.Member;

import iaas.enums.StatusEnum;


@Entity
@Table(name = "bbs_topic")
public class Topic implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Long id;
	private String name;
	private String content;
	private Integer pv;					//点击数
	private Integer isRecommend;	// 精华
	private Integer status;
	private String creator;
	private Date createTime;
	private Date recommendTime;
	private Board board;
	private Member member; 
	
	private List<TopicPic> topicPicList = new ArrayList<TopicPic>();
	private List<Reply> replyList = new ArrayList<Reply>();
	private List<TopicAppraise> topicAppraiseList = new ArrayList<TopicAppraise>();
	
	/* ---------------- method ----------------*/
	
	public Topic(){
	}
	
	public Topic(Long id){
		this.id=id;
	}
	
	/* ---------------- getter/setter ----------------*/
	
	@Transient
	public Integer getReplyNum(){
		int num = 0;
		for (Reply reply : replyList) {
			if(reply.getStatus()==StatusEnum.NORMAL.getValue()){
				num++;
			}
		}
		return num;
	}
	
	@Transient
	public Integer getSupportNum(){
		int num = 0;
		for (TopicAppraise temp : topicAppraiseList) {
			if(temp.getStatus()==StatusEnum.NORMAL.getValue() && temp.getType() == TopicAppraiseEnum.SUPPORT.getValue()){
				num++;
			}
		}
		return num;
	}
	
	@Transient
	public Integer getAgainstNum(){
		int num = 0;
		for (TopicAppraise temp : topicAppraiseList) {
			if(temp.getStatus()==StatusEnum.NORMAL.getValue() && temp.getType() == TopicAppraiseEnum.AGAINST.getValue()){
				num++;
			}
		}
		return num;
	}
	
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "content")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	public Integer getPv() {
		return pv;
	}

	public void setPv(Integer pv) {
		this.pv = pv;
	}

	@Column(name = "status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	@Column(name = "is_recommend")
	public Integer getIsRecommend() {
		return isRecommend;
	}

	public void setIsRecommend(Integer isRecommend) {
		this.isRecommend = isRecommend;
	}

	@Column(name = "creator")
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@Column(name = "recommend_time")
	public Date getRecommendTime() {
		return recommendTime;
	}

	public void setRecommendTime(Date recommendTime) {
		this.recommendTime = recommendTime;
	}

	@ManyToOne
	@JoinColumn(name = "board_id")
	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}

	@ManyToOne
	@JoinColumn(name = "member_id")
	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}
	
	@OneToMany(mappedBy = "topic")
	@JsonIgnore
	public List<TopicPic> getTopicPicList() {
		return topicPicList;
	}
	
	public void setTopicPicList(List<TopicPic> topicPic){
		this.topicPicList = topicPic;
	}
	@OneToMany(mappedBy = "topic")
	@JsonIgnore
	public List<Reply> getReplyList() {
		return replyList;
	}
	
	public void setReplyList(List<Reply> reply){
		this.replyList = reply;
	}
	@OneToMany(mappedBy = "topic")
	@JsonIgnore
	public List<TopicAppraise> getTopicAppraiseList() {
		return topicAppraiseList;
	}
	
	public void setTopicAppraiseList(List<TopicAppraise> topicAppraise){
		this.topicAppraiseList = topicAppraise;
	}
	
}
